package org.example.java8.future;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 夏焰波
 * @date 2020-07-15 23:08
 */
//34CompletableFuture之supplyAsync详细介绍
public class CompletableFutureInAction3 {
    public static void main(String[] args) throws InterruptedException {
        //test();
        test2();

    }

    private static void test() {
        //不是守护线程，不会退出
        ExecutorService executor = Executors.newFixedThreadPool(2);
        executor.execute(() -> System.out.println("test..."));
        //要退出只有把executor关掉
        executor.shutdown();
    }

    private static void test2() {
        //实现工厂接口，设置守护线程
        Executor executor = Executors.newFixedThreadPool(2, r -> {
            Thread t = new Thread(r);
            //设置守护线程
            t.setDaemon(true);
            return t;
        });

        executor.execute(() -> System.out.println("test..."));

    }
}
